﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MyHotel_DTO;
using System.Data.SqlClient;
using MyHotel_Common;
using System.Data;

namespace MyHotel_DAO
{
    public class PhieuThuePhongDAO :DAO
    {
        protected override object createObjectFromDatarow(System.Data.DataRow row)
        {
            PhieuThuePhong phieuThue = new PhieuThuePhong();
            phieuThue.DonGia = int.Parse(row["DonGia"].ToString());
            phieuThue.MaKH = int.Parse(row["MaKH"].ToString());
            phieuThue.MaPhieu = int.Parse(row["MaPhieu"].ToString());
            phieuThue.MaPhong = int.Parse(row["MaPhong"].ToString());
            phieuThue.NgayThue = DateTime.Parse(row["NgayThue"].ToString());
            phieuThue.NgayTra = DateTime.Parse(row["NgayTra"].ToString());
            phieuThue.SoTien = int.Parse(row["SoTien"].ToString());


            return phieuThue;
        }

        public bool themPhieuThuePhong(PhieuThuePhong phieuThue)
        {
            string nameProc = "SP_THEM_PHIEUTHUEPHONG";
            SqlParameter[] para = new SqlParameter[4];
            para[0] = new SqlParameter("@DonGia", phieuThue.DonGia);
            para[1] = new SqlParameter("@MAKH", phieuThue.MaKH);
            para[2] = new SqlParameter("@MaPhong", phieuThue.MaPhong);
            para[3] = new SqlParameter("@NgayThue", phieuThue.NgayThue);
            


            return (DataProvider.executeStoreProcedureNonQuery(nameProc, para) > 0);
        }

        public PhieuThuePhong getPhieuThuePhong(int maPhong)
        {
            string nameProc = "SP_GET_PHIEUTHUEPHONG";
            
            DataTable dt = DataProvider.executeStoreProcedureQuery(nameProc, new SqlParameter("@MaPhong", maPhong));
            return (PhieuThuePhong)createObjectFromDatarow(dt.Rows[0]);
        }

        public bool suaPhieuThuePhong(PhieuThuePhong phieuThue)
        {
            string nameProc = "SP_SUA_PhieuTHUEPHONG";
            SqlParameter[] para = new SqlParameter[3];
            para[0] = new SqlParameter("@MAPHIEU", phieuThue.MaPhieu);
            para[1] = new SqlParameter("@NGAYTRA", phieuThue.NgayTra);
            para[2] = new SqlParameter("@SOTIEN", phieuThue.SoTien);
                        
            return (DataProvider.executeStoreProcedureNonQuery(nameProc, para) > 0);
        }
    }
}
